<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<html>
	 <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
        <meta name="format-detection" content="telephone=no">
        <meta charset="UTF-8">
        <meta name="description" content="Violate Responsive Admin Template">
        <meta name="keywords" content="Super Admin, Admin, Template, Bootstrap">
        <link href="<%=path %>/assets2/js/bootstrap-table.css" rel="stylesheet">
        <script src="<%=path %>/assets2/js/jquery-1.11.1.min.js"></script>
        <script src="<%=path %>/assets2/js/bootstrap-table.js"></script>
   		<script src="<%=path %>/assets2/js/locale/bootstrap-table-zh-CN.js"></script>
   		<script src="<%=path %>/assets2/js/bootstrap.min.js"></script>
    </head>
<div class="row">
	<ol class="breadcrumb">
		<li><a href="<%=path%>/index"><span
				class="glyphicon glyphicon-home"></span></a></li>
		<li class="active">用户管理</li>
	</ol>
</div>

<div class="panel panel-default">
	<div class="panel-heading">用户列表</div>
	<div class="panel-body">
		<form id="formSearch" class="form-horizontal">
			<input type="hidden" id="userType" name="userType" value="7">
			<div class="form-group" style="margin-top: 15px">
				<label class="control-label col-sm-2"
					for="realName">真实姓名</label>
				<div class="col-sm-2">
					<input type="text" class="form-control" id="realName">
				</div>
				<div class="col-sm-1" style="text-align: left;">
					<button type="button" style="margin-left: 50px" id="btn_query"
						class="btn btn-primary" onclick="serachUser()">查询</button>
				</div>
			</div>
		</form>
		<br>
		<div style="text-align: left;">
			<button type="button" class="btn btn-primary"
				onclick="addUsers()">
				<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增角色
			</button>
		</div><br>
		<div class="tab-wrapper tab-primary">
			<ul class="nav nav-tabs">
				<li class="active"><a href="#profile1"
					onclick="$('#userType').val(7);serachUser();" data-toggle="tab">论坛</a></li>
				<li class=""><a href="#profile1"
					onclick="$('#userType').val(8);serachUser();" data-toggle="tab">小记者</a></li>
				<li class=""><a href="#profile2"
					onclick="$('#userType').val(9);serachUser();" data-toggle="tab">社团</a></li>
			</ul>
			<button style="float: right; margin-right: 40px; margin-top: -40px"
				onclick="serachUser()" class="btn btn-default" type="button" title="刷新">
				<i class="glyphicon glyphicon-refresh icon-refresh"></i>
			</button>
		</div>
		<table id="tabId"></table>
	</div>
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="myModal" aria-labelledby="myModalLabel" aria-hidden="true" style="margin-top: 8%;">
<div class="modal-dialog" role="document">
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal"
				aria-label="Close">
				<span aria-hidden="true">&times;</span>
			</button>
			<h4 class="modal-title" id="myModalTitle"></h4>
		</div>
		<div class="modal-body" id="myModalBody">
			
		</div>
	</div>
</div>
</div>
   <script type="text/javascript">
   $(function () {
	    //1.初始化Table
	    var oTable = new TableInit();
	    oTable.Init();
	    //2.初始化Button的点击事件
	    var oButtonInit = new ButtonInit();
	    oButtonInit.Init();
	});
	var TableInit = function () {
	    var oTableInit = new Object();
	    //初始化Table
	    oTableInit.Init = function () {
	        $('#tabId').bootstrapTable({
	            url: '<%=path %>/liveManager/getAllUserInfoList',         //请求后台的URL（*）
	            method: 'get',                      //请求方式（*）
	            toolbar: '#toolbar',                //工具按钮用哪个容器
	            striped: false,                      //是否显示行间隔色
	            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
	            pagination: true,                   //是否显示分页（*）
	            sortable: false,                     //是否启用排序
	            sortOrder: "asc",                   //排序方式
	            queryParams: oTableInit.queryParams,//传递参数（*）
	            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
	            pageNumber:1,                       //初始化加载第一页，默认第一页
	            pageSize: 10,                       //每页的记录行数（*）
	            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
	            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
	            strictSearch: false,
	            showColumns: false,                  //是否显示所有的列
	            showRefresh: false,                  //是否显示刷新按钮
	            minimumCountColumns: 2,             //最少允许的列数
	            clickToSelect: false,                //是否启用点击选中行
	            uniqueId: "userId",                     //每一行的唯一标识，一般为主键列
	            showToggle:false,                    //是否显示详细视图和列表视图的切换按钮
	            cardView: false,                    //是否显示详细视图
	            detailView: false,                   //是否显示父子表
	            columns: [/* {
	            	checkbox: true, // 显示一个勾选框
	                align: 'center', // 居中显示
	                
	            }, */ {
	                field: 'loginName',
	                title: '登录名称',
	                width:100,
	                align: 'center', // 左右居中
	                valign: 'middle' // 上下居中
	            }, {
	                field: 'realName',
	                title: '真实姓名',
	                align: 'center', // 左右居中
	                valign: 'middle' // 上下居中
	            }, {
	                field: 'idNo',
	                title: '身份证号码',
	                align: 'center', // 左右居中
	                valign: 'middle' // 上下居中
	            }, {
	                field: 'phone',
	                title: '手机号码',
	                align: 'center', // 左右居中
	                valign: 'middle' // 上下居中
	            },{
	                field: 'userId',
	                title: '操作',
	                align: 'center', // 左右居中
	                valign: 'middle', // 上下居中
	                formatter: operateFormatter //自定义方法，添加操作按钮
	            }]
	        });
	    };

	//得到查询的参数
	oTableInit.queryParams = function (params) {
	        var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
	            limit: params.limit,   //页面大小
	            offset: params.offset,  //页码
	            realName: $("#realName").val(),
	            userType: $("#userType").val(),
	        };
	        return temp;
	    };
	    return oTableInit;
	};
	//查询
	function serachUser() {
        $("#tabId").bootstrapTable('refresh',{pageNumber:1});
    };
	var ButtonInit = function () {
	    var oInit = new Object();
	    var postdata = {};
	    oInit.Init = function () {
	        //初始化页面上面的按钮事件
	    };
	    return oInit;
	};
	//操作判断
	function operateFormatter(value, row, index) {
		var str=''
		return str;
	};
	//禁用用户
	function disabledUsers(userId){
		swal({ 
			  title: "是否禁用该用户吗？", 
			  type: "warning",
			  showCancelButton: true, 
			  confirmButtonColor: "#DD6B55",
			  confirmButtonText: "确定禁用！", 
			  cancelButtonText: "取消禁用！",
			  closeOnConfirm: false, 
			  closeOnCancel: true
			},
			function(isConfirm){ 
			    if(isConfirm){
			    	$.ajax({
						 type:"POST",
				         url: "<%=path %>/manager/disabledUsers?userId="+userId,
				         success: function(data,status,xhr){
				        	 if(data==1){
				        		 swal({ 
						   			  title: "提交成功", 
						   			  text: "禁用成功", 
						   			  type: "success",
						   			},function(){
						        		 $("#tabId").bootstrapTable('refresh');
						   			});
				        		 
				        	 }else{
				        		 swal({ 
						   			  title: "提交失败", 
						   			  text: "禁用失败", 
						   			  type: "error",
						   			}); 
				        	 }
				         }
					})
			    }
			});
	};
	//启用用户
	function enabledUsers(userId){
		swal({ 
			  title: "是否启用该用户吗？", 
			  type: "warning",
			  showCancelButton: true, 
			  confirmButtonColor: "#DD6B55",
			  confirmButtonText: "确定启用！", 
			  cancelButtonText: "取消启用！",
			  closeOnConfirm: false, 
			  closeOnCancel: true
			},
			function(isConfirm){ 
			    if(isConfirm){
			    	$.ajax({
						 type:"POST",
				         url: "<%=path %>/manager/enabledUsers?userId="+userId,
				         data: {
					        	"state":0
					        },
				         success: function(data,status,xhr){
				        	 if(data==1){
				        		 swal({ 
						   			  title: "提交成功", 
						   			  text: "启用成功", 
						   			  type: "success",
						   			},function(){
						        		 $("#tabId").bootstrapTable('refresh');
						   			});
				        		 
				        	 }else{
				        		 swal({ 
						   			  title: "提交失败", 
						   			  text: "启用失败", 
						   			  type: "error",
						   			}); 
				        	 }
				         }
					})
			    }
			});
	};
	//激活用户的二手发布功能
	function activateUsersOfFunctions(userId){
		swal({ 
			  title: "是否激活该用户的二手发布功能吗？", 
			  type: "warning",
			  showCancelButton: true, 
			  confirmButtonColor: "#DD6B55",
			  confirmButtonText: "确定激活！", 
			  cancelButtonText: "取消激活！",
			  closeOnConfirm: false, 
			  closeOnCancel: true
			},
			function(isConfirm){ 
			    if(isConfirm){
			    	$.ajax({
						 type:"POST",
				         url: "<%=path %>/manager/enabledUsers?userId="+userId,
				         data: {
					        	"state":1
					        },
				         success: function(data,status,xhr){
				        	 if(data==1){
				        		 swal({ 
						   			  title: "提交成功", 
						   			  text: "激活成功", 
						   			  type: "success",
						   			},function(){
						        		 $("#tabId").bootstrapTable('refresh');
						   			});
				        		 
				        	 }else{
				        		 swal({ 
						   			  title: "提交失败", 
						   			  text: "激活失败", 
						   			  type: "error",
						   			}); 
				        	 }
				         }
					})
			    }
			});
	};
	//冻结用户的二手发布功能
	function unActivateUsersOfFunctions(userId){
		swal({ 
			  title: "是否冻结该用户的二手发布功能吗？", 
			  type: "warning",
			  showCancelButton: true, 
			  confirmButtonColor: "#DD6B55",
			  confirmButtonText: "确定冻结！", 
			  cancelButtonText: "取消冻结！",
			  closeOnConfirm: false, 
			  closeOnCancel: true
			},
			function(isConfirm){ 
			    if(isConfirm){
			    	$.ajax({
						 type:"POST",
				         url: "<%=path %>/manager/unActivateUsersOfFunctions?userId="+userId,
				         success: function(data,status,xhr){
				        	 if(data==1){
				        		 swal({ 
						   			  title: "提交成功", 
						   			  text: "冻结成功", 
						   			  type: "success",
						   			},function(){
						        		 $("#tabId").bootstrapTable('refresh');
						   			});
				        		 
				        	 }else{
				        		 swal({ 
						   			  title: "提交失败", 
						   			  text: "冻结失败", 
						   			  type: "error",
						   			}); 
				        	 }
				         }
					})
			    }
			});
	};
	function addUsers(){
		$('#myModalTitle').html("用户角色创建");
		$("#myModalBody").load("<%=path %>/jsp/liveManager/addUsers.jsp",function(data,status,xhr){
	        if(xhr.getResponseHeader("sessionstatus")=='timeout'){
	        	window.location.href=context_path+'/login';
	        }
		});
		$('#myModal').modal('show');
	}
	
	
   </script>
</html>